<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

use Illuminate\Support\Facades\DB;

class PlacardController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth:admin');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //查询首页告示
        $placard = DB::table('placard')
            ->select('id', 'position1', 'position2', 'position3', 'position4', 'position5')
            ->first();

        return view('admin.placard.create',['placard' => $placard]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {

        //验证表单
        $this->validate($request, [
            'position1' => ['required','string','max:20'],
            'position2' => ['required','string','max:20'],
            'position3' => ['required','string','max:20'],
            'position4' => ['required','string','max:20'],
            'position5' => ['required','string','max:20'],
        ]);

        //更新购买成功到数据库
        DB::table('placard')
            ->update([
                'position1' => $request->position1,
                'position2' => $request->position2,
                'position3' => $request->position3,
                'position4' => $request->position4,
                'position5' => $request->position5,
            ]);

        return response()->json(['message' => '修改成功。', 'success' => 'true']);

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
